package com.ibiaoke.marketing.service;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.marketing.dao.MarketingDao;
import com.ibiaoke.marketing.entity.Marketing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MarketingServiceImpl implements MarketingService {

    @Autowired
    private MarketingDao marketingDao;

    /**
     * 添加优惠券营销活动
     * @param marketing
     * @return
     */
    @Override
    public Integer saveMarketing(Marketing marketing) {
        marketing.setCreateTime(new Date());
        marketing.setUpdateTime(new Date());
        marketing.setDelStatus(CommonConsts.NO);
        return marketingDao.insertSelective(marketing);
    }

    /**
     * 修改优惠券营销活动
     * @param marketing
     * @return
     */
    @Override
    public Integer updateMarketing(Marketing marketing) {
        AssertUtils.notNull(marketing.getMarketingId(), "营销活动id不能为空");
        marketing.setUpdateTime(new Date());
        return marketingDao.updateByPrimaryKeySelective(marketing);
    }

    /**
     * 查询优惠券列表
     * @param marketingName
     * @param page
     * @return
     */
    @Override
    public List<Marketing> listMarketing(String marketingName, Page page) {
        return marketingDao.listMarketing(marketingName, page);
    }

    /**
     * 获取营销详情
     * @param marketingId
     * @return
     */
    @Override
    public Marketing getMarketing(Integer marketingId) {
        AssertUtils.notNull(marketingId, "营销Id不能为空值");
        return marketingDao.selectByPrimaryKey(marketingId);
    }

    /**
     * 逻辑删除营销活动
     * @param marketingId
     * @return
     */
    @Override
    public int deleteMarketing(Integer marketingId) {
        AssertUtils.notNull(marketingId, "营销Id不能为空值");
        return marketingDao.deleteMarketing(marketingId);
    }
}
